const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    index: 0,
    isDuaration:true,
    formdata: '',
    modalName: null,
    searchvalue: '',
    picker: [],
    selectPro: '',
    ids: [],
    selectProId: '',
    inputValue:''
  },
  onLoad() {
    setTimeout(() => {
      this.setData({
        isDuaration: false,

      })
    }, 1000)
    let open_id = wx.getStorageSync('user_new')
    console.log(open_id)
  }, 
  // 楼盘
  searchlist(e) {
    this.setData({
      searchvalue: e.detail.value
    })
  },
 
  //搜索框内容
  searchdesc() {
    var that = this;
    var setid = app.globalData.cityCode;
    var searchvalue = that.data.searchvalue;
    if (searchvalue == '') {
      wx.showToast({
        title: '请输入内容',
        duration: 1000,
        icon: 'none'
      })
    } else {
      wx.showLoading({
        title: '加载中',
      })
      app.core('get', 'getNewHouseProjectBySiteId?siteId=' + setid + '&projectName=' + searchvalue, '', (res) => {
        console.log(res.data)
        // let proName = []
        // let proId = []
        // for (let i in res.data) {
        //   proName.push(res.data[i].projectName)
        //   proId.push(res.data[i].id)
        // }
        // console.log(proName)
        // console.log(proId)
        // this.setData({
        //   picker: proName,
        //   proId: proId
        // })
        this.setData({picker:res.data})
        if (res.data == '') {
          wx.showToast({
            title: '暂无相关信息,请输入正确楼盘，支持模糊搜索',
            duration: 2000,
            icon: 'none'
          })
          return false
        }
        wx.hideLoading()
      })
    }
  },
  selectitem(e) {
    console.log(e.detail.value,555555)
    let ids = e.detail.value

    this.setData({
      ids: ids
    })
   
  },
  // PickerChange
  // PickerChange(e) {
  //   let picker = this.data.picker
  //   let proId = this.data.proId
  //   console.log(picker[e.detail.value])
  //   this.setData({
  //     index: e.detail.value,
  //     selectPro: picker[e.detail.value],
  //     selectProId: proId[e.detail.value]
  //   })
  //   console.log(proId[e.detail.value])
  // },
  // 增加楼盘
  addBuilding() {
    var openid = wx.getStorageSync('user_new');
    var vm = this;
    var searchvalue = vm.data.searchvalue;
    var idsArr = vm.data.ids;
    if(idsArr.length == 0) {
      wx.showToast({
        title: '请绑定楼盘',
        icon: 'none',
        duration: 2000
      });
      return false;
    }
    var newhouse_project_id = idsArr.join(',')
    // return false
    if (searchvalue == '') {
      wx.showToast({
        title: '输入不能为空',
        icon: 'none',
        duration: 2000
      });
      return false;
    } else {   
      app.core('post', 'adviserAppendProject', {
        'open_id': openid,
        'newhouse_project_ids': newhouse_project_id
      }, (res) => {
        console.log(res);
        if (res.resultCode == 200) {
          wx.showToast({
            title: '增加成功',
            icon: 'none',
            duration: 1000
          });
          setTimeout(() => {
            wx.switchTab({
              url: '/pages/member/index',
            })
          },500)
        } else {
          wx.showToast({
            title: '网络出错！',
            icon: 'none',
            duration: 2000
          });
        }
      },
        (err) => {
          console.log(err)
        }
      )

    }

  }
})